<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 *      [PinTuXiu] (C)2001-2099 ONightjar.com Pintuxiu.com.
 *      This is NOT a freeware, use is subject to license terms
*/

class welcome_api {

	public function getLastest20($days){
		$result = pcache('r', 'lastest_shares');
		if(!$result){
			$result = $this->updateLastest20($days);
		}
		return $result;
	}

	public function updateLastest20($days){
		$shareapi = load_api('share');
		$conditions['orgin_post']=1;
		$days = $days ? $days:7;
		$conditions['gt_time'] = TIMESTAMP - 24*3600*$days;
		$result = $shareapi->search($conditions,1,7," ptx_share.total_click DESC ");
		pcache('w','lastest_shares',$result,24*3600*$days);
		return $result;
	}

	public function getHotestUser($num=4){
		$users = pcache('r', 'hotest_user');
		if(!$users){
			$setting = load_api('setting')->getSetting('optimizer');
			$users = load_db('user')->searchWithShare(null,1,$num,null,' ptx_user.total_follower DESC ');
			$time = $setting['cachetime_homeuser']?$setting['cachetime_homeuser']:3600;
			pcache('w','hotest_user',$users,$time);
		}
		return $users;
	}

}

